package common.io.console.guice;

import com.google.inject.AbstractModule;
import com.google.inject.Provides;
import common.io.console.ConsoleDevice;
import common.io.console.StreamDevice;
import common.io.console.Terminal;

/**
 * Created by Gerardo on 2/24/14.
 */
public class TerminalModule extends AbstractModule {
	@Override
	protected void configure() {
	}

	@Provides
	private Terminal getTerminal() {
		return (System.console() == null) ? createStreamDevice() : createConsoleDevice();
	}

	private StreamDevice createStreamDevice() {
		return new StreamDevice(System.in, System.out);
	}

	private ConsoleDevice createConsoleDevice() {
		return new ConsoleDevice(System.console());
	}
}
